package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceBuildLogDAO;
import com.ourteam.workspace.dao.WorkspaceBuildLog;
import com.ourteam.workspace.dao.WorkspaceBuildLogDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:34 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceBuildLogDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceBuildLogDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceBuildConfigId,
        BuildTime,
        BuildLog,
        BuildResult,
        BuildOutputPath,
        Status,
        Remarks,
        ProductionName,
        ProductionType
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceBuildConfigId,
        _DataObjectProperty.BuildTime,
        _DataObjectProperty.BuildLog,
        _DataObjectProperty.BuildResult,
        _DataObjectProperty.BuildOutputPath,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.ProductionName,
        _DataObjectProperty.ProductionType
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceBuildLog, WorkspaceBuildLogDAOQueryBean> daoHelper;

  public AbstractWorkspaceBuildLogDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<WorkspaceBuildLog, WorkspaceBuildLogDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.EntityName)
          .append(" workspace_build_config ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.EntityName + ".",
              "workspace_build_config."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceBuildConfigId);

      relatedJoinSQLBuffer.append(" AND ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.ProductionName,
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.EntityName + ".",
              "workspace_build_config."));
      relatedJoinSQLBuffer.append(" = ").append(ProductionName);

      relatedJoinSQLBuffer.append(" AND ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.ProductionType,
              com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO.EntityName + ".",
              "workspace_build_config."));
      relatedJoinSQLBuffer.append(" = ").append(ProductionType);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceBuildLog
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceBuildLog aWorkspaceBuildLog) throws Exception {

    if (aWorkspaceBuildLog == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceBuildLog.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceBuildLog
   * @throws Exception
   */
  public void insert(WorkspaceBuildLog aWorkspaceBuildLog) throws Exception {

    super.doInsert(aWorkspaceBuildLog);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceBuildLog
   * @throws Exception
   */
  public void batchInsert(WorkspaceBuildLog[] aWorkspaceBuildLogs) throws Exception {

    super.doBatchInsert(aWorkspaceBuildLogs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceBuildLogDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceBuildLog aWorkspaceBuildLog) throws Exception {

    delete(aWorkspaceBuildLog.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceBuildLog
   * @throws Exception
   */
  public void update(WorkspaceBuildLog aWorkspaceBuildLog) throws Exception {

    if (aWorkspaceBuildLog.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceBuildLog);

    WorkspaceBuildLog tempObj = findById(aWorkspaceBuildLog.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceBuildLog, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceBuildLogs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceBuildLog[] aWorkspaceBuildLogs) throws Exception {

    super.doBatchUpdate(aWorkspaceBuildLogs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceBuildLog
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(WorkspaceBuildLog aWorkspaceBuildLog, WorkspaceBuildLogDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceBuildLog, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceBuildLogDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceBuildLog aWorkspaceBuildLog) throws Exception {

    if (aWorkspaceBuildLog.getProductionName() == null) {
      throw new Exception("The WorkspaceBuildLog.productionName value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getProductionType() == null) {
      throw new Exception("The WorkspaceBuildLog.productionType value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getBuildTime() == null) {
      throw new Exception("The WorkspaceBuildLog.buildTime value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getBuildLog() == null) {
      throw new Exception("The WorkspaceBuildLog.buildLog value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getBuildResult() == null) {
      throw new Exception("The WorkspaceBuildLog.buildResult value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getBuildOutputPath() == null) {
      throw new Exception("The WorkspaceBuildLog.buildOutputPath value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getStatus() == null) {
      throw new Exception("The WorkspaceBuildLog.status value is not allow NULL");
    }

    if (aWorkspaceBuildLog.getRemarks() == null) {
      throw new Exception("The WorkspaceBuildLog.remarks value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceBuildLog findById(final long id) throws Exception {

    WorkspaceBuildLogDAOQueryBean queryBean = new WorkspaceBuildLogDAOQueryBean();

    WorkspaceBuildLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceBuildLog[] WorkspaceBuildLogs = query(queryBean);

    if (WorkspaceBuildLogs.length == 0) {
      return null;
    } else {
      return WorkspaceBuildLogs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceBuildLog[]
   * @throws Exception
   */
  public WorkspaceBuildLog[] query(WorkspaceBuildLogDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceBuildLogRowMapper());

    return (WorkspaceBuildLog[]) result.toArray(new WorkspaceBuildLog[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceBuildLogDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceBuildLogDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceBuildLog[] aWorkspaceBuildLogs, WorkspaceBuildLogDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceBuildLogs, queryBean);
  }

  public void synchronize(
      WorkspaceBuildLog[] aWorkspaceBuildLogs,
      WorkspaceBuildLogDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceBuildLog> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceBuildLogs, queryBean, callBack);
  }

  public static class JdbcWorkspaceBuildLogRowMapper implements RowMapper<WorkspaceBuildLog> {

    public WorkspaceBuildLog mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceBuildLog object = new WorkspaceBuildLog();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceBuildConfigId = null;

        workspaceBuildConfigId = resultSet.getObject(columnIndex++);

        object.setWorkspaceBuildConfigIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceBuildConfigId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceBuildConfigId, workspaceBuildConfigId);
        }

        Object buildTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          buildTime = resultSet.getTimestamp(columnIndex++);

        } else {
          buildTime = resultSet.getObject(columnIndex++);
        }

        object.setBuildTimeNull(resultSet.getBoolean(columnIndex++));

        if (buildTime != null) {

          setBeanValue(object, _DataObjectProperty.BuildTime, buildTime);
        }

        Object buildLog = null;

        buildLog = resultSet.getObject(columnIndex++);

        object.setBuildLogNull(resultSet.getBoolean(columnIndex++));

        if (buildLog != null) {

          setBeanValue(object, _DataObjectProperty.BuildLog, buildLog);
        }

        Object buildResult = null;

        buildResult = resultSet.getObject(columnIndex++);

        object.setBuildResultNull(resultSet.getBoolean(columnIndex++));

        if (buildResult != null) {

          setBeanValue(object, _DataObjectProperty.BuildResult, buildResult);
        }

        Object buildOutputPath = null;

        buildOutputPath = resultSet.getObject(columnIndex++);

        object.setBuildOutputPathNull(resultSet.getBoolean(columnIndex++));

        if (buildOutputPath != null) {

          setBeanValue(object, _DataObjectProperty.BuildOutputPath, buildOutputPath);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object productionName = null;

        productionName = resultSet.getObject(columnIndex++);

        object.setProductionNameNull(resultSet.getBoolean(columnIndex++));

        if (productionName != null) {

          setBeanValue(object, _DataObjectProperty.ProductionName, productionName);
        }

        Object productionType = null;

        productionType = resultSet.getObject(columnIndex++);

        object.setProductionTypeNull(resultSet.getBoolean(columnIndex++));

        if (productionType != null) {

          setBeanValue(object, _DataObjectProperty.ProductionType, productionType);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
